Previous Book Contents Next

Inside Macintosh: Using JBindery


The Classpath Panel

Figure 1-3 shows the Classpath panel of JBindery, which displays the class paths used to search for Java classes.

By default, JBindery searches the MRJ Libraries folder when looking for classes. However, you can use the Classpath panel to specify additional class paths in a manner similar to setting the CLASSPATH Java environment variable. Any class paths you specify do not replace the default, but are appended to the class path list. These path entries are searched in the order they appear in the list. The MRJ Libraries folder is always searched last.

Figure 1-3 The Classpath panel

You can add any of the following entries to the class path list:

Note that if your class files have names longer than the 31 characters allowed by the Mac OS, you can bypass this limitation by storing them in a .zip or .jar archive.

You can change the search position of any item in the class path list by selecting it and then using the up and down arrows. You can remove a selected item by using the Delete button. Clicking the Edit... button allows you to edit the current selection.

Adding an Alias

An alias is a small file that represents another file stored in a different location. Typically, you use them to simplify organizing files or to allow easy access to large or dynamic files that reside on a file server. In most cases, you can handle an alias just as you would the original file. For example, you could open the original file by double-clicking on its alias.

Aliases provide a quick and easy way to set up class paths if you plan to use JBindery to simply execute a Java application (for example, during development). However, aliases are generally not portable. Since aliases often store information about the local file system (the name of the hard drive, and so on), the Finder may not be able to resolve the alias if it is moved to another computer. For this reason, you should not add class paths as aliases if you plan to run your Java application on multiple computers.

You can add an alias to your class path using any of the following methods:

Adding a Class Path Manually

The Add Manually button brings up a dialog box as shown in Figure 1-4. You must specify the location of a folder or an uncompressed .zip or .jar file as a file-based URL . You can also use this dialog box to specify unexpanded .zip or .jar files contained in a virtual file system, which is described in Adding a Virtual File System .

The disk name /$APPLICATION/ is an Apple-specific designation that you can use in your file-based URL to indicate the folder containing the running application. For example, if you wanted to include a folder NewClasses contained in application's folder, you would designate the URL as file:///$APPLICATION/NewClasses . The /$APPLICATION/ designation corresponds to the location of JBindery or the packaged Java application, not the location of the Java classes.

Adding classes manually allows for greater portability across computers than using aliases. The class path file:///$APPLICATION/NewClasses will always work as long as the NewClasses folder is in the same folder as the application.

Figure 1-4 The Add Manually dialog box

Adding a Virtual File System

In addition to specifying class paths to files or folders, you can specify a path to a virtual file system (VFS). A virtual file system lets you package Java classes and any other information your Java application requires (such as images or sound clips) in one file. That is, you can store your Java application as one easily portable package.

Items in a virtual file system are stored as though they were in a file hierarchy, so the Java application can access them normally. For example, say you have a Java program that requires two class files, Upper.class and Working.class , and a JPEG image photo.jpg contained in a folder called Images . By specifying these in a virtual file system, you can include all of these files in one application file and preserve the file hierarchy as well. Real and virtual file systems compares a virtual file system to a real one.

Note

The contents of a virtual file directory are stored in the data fork of the application file as an uncompressed read-only .zip archive. For more information about data forks, see Mac OS Resources.

Figure 1-5 Real and virtual file systems

To create a virtual file system, you must do the following:

  1. Add the root folder of the folder hierarchy to the class path list.
  2. Select the folder in the class path list and click the Make VFS button.

For example, in Real and virtual file systems , the root folder is MyFolder . You can add MyFolder to the class path list by dragging the folder to the list or by selecting the Add Folder... button. Selecting MyFolder in the class path list and clicking the Make VFS Button then makes MyFolder the virtual file system.

Note that only one folder may be designated as a virtual file system.

Warning

The folder you designate as the root of your virtual file system should contain only the files you want to package. For example, you should make sure that neither JBindery nor the resulting packaged application is contained within the root folder. Doing so will cause your packaged application to act unpredictably at runtime.

The Expand .zip and .jar Files checkbox specifies whether you want to extract Java classes from .zip and .jar files when packaging them in the application. For example, say you have a .zip file Airline.zip that contains First.class and Economy.class . If you don't specify expanding the .zip file, the packaged application will only contain Airline.zip . Otherwise, JBindery extracts the Java classes and places First.class and Economy.class in the packaged application.

In most cases you should choose to extract your files from .zip and .jar packages. If you do not, however, you must manually add a class path to each unexpanded package using the Add Manually dialog box (as shown in Figure 1-4. The class path should be prefixed with file:///$VFS/ . Select the OK button when finished.


Previous Book Contents Next

© Apple Computer, Inc.
06 AUGUST 1998